package com.itheima.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.common.R;
import com.itheima.common.TokenHolder;
import com.itheima.domian.MyPage;
import com.itheima.domian.Orders;
import com.itheima.domian.vo.OrderVo;
import com.itheima.domian.vo.QueryVo;
import com.itheima.mapper.client.OrderMapper;
import com.itheima.service.client.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author 12441
 * @Date 2022/8/18 14:52
 * @Version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private OrderMapper orderMapper;


    @GetMapping("/userPage")
    public R<IPage> page(HttpServletRequest httpServerRequest){

            String name = httpServerRequest.getParameter("name");
            Integer page1 = Integer.valueOf(httpServerRequest.getParameter("page"));
            Integer size = Integer.valueOf(httpServerRequest.getParameter("pageSize"));

            Page<OrderVo> page = new Page<>(page1, size);

            IPage<OrderVo> orderVoIPage = orderService.findByPage(page, new QueryWrapper<>());

            log.info(""+page.getRecords());

            return R.success(orderVoIPage,"查询成功");

     }
    @PostMapping("/submit")
    public R<String>submitOrder(@RequestBody Orders order){
        String currentId = TokenHolder.getCurrentId();

        orderService.submitOrder(order,currentId);

        return R.success("提交成功");
    }

}